<template lang="pug">
  div
    el-descriptions(title="用户信息"  :column="6" size="medium" border)
      el-descriptions-item(label="等级") {{data.hacking}}
      el-descriptions-item(label="money") {{money}}
      el-descriptions-item(label="HP") {{data.hp+'/'+data.max_hp}}
      el-descriptions-item(label="defense") {{data.defense}}
      el-descriptions-item(label="dexterity") {{data.dexterity}}
      el-descriptions-item(label="agility") {{data.agility}}
      el-descriptions-item(label="charisma") {{data.charisma}}
      el-descriptions-item(label="intelligence") {{data.intelligence}}
      el-descriptions-item(label="hacking_chance_mult") {{data.hacking_chance_mult.toFixed(2)}}
      el-descriptions-item(label="hacking_speed_mult") {{data.hacking_speed_mult.toFixed(2)}}
      el-descriptions-item(label="hacking_money_mult") {{data.hacking_money_mult.toFixed(2)}}
      el-descriptions-item(label="hacking_grow_mult") {{data.hacking_grow_mult.toFixed(2)}}
      el-descriptions-item(label="hacking_exp") {{data.hacking_exp}}
      el-descriptions-item(label="hacking_mult") {{data.hacking_mult.toFixed(2)}}
      el-descriptions-item(label="hacking_exp_mult") {{data.hacking_exp_mult.toFixed(2)}}
      el-descriptions-item(label="faction_rep_mult") {{data.faction_rep_mult.toFixed(2)}}
      el-descriptions-item(label="company_rep_mult") {{data.company_rep_mult.toFixed(2)}}
      el-descriptions-item(label="numPeopleKilled") {{data.numPeopleKilled}}
      el-descriptions-item(label="city") {{data.city}}
      el-descriptions-item(label="location") {{data.location}}
      el-descriptions-item(label="companyName") {{data.companyName}}
      el-descriptions-item(label="currentWorkFactionName") {{data.currentWorkFactionName}}
      el-descriptions-item(label="currentWorkFactionDescription") {{data.currentWorkFactionDescription}}
      el-descriptions-item(label="createProgramName") {{data.createProgramName}}
      el-descriptions-item(label="hasWseAccount") {{data.hasWseAccount}}
      el-descriptions-item(label="hasTixApiAccess") {{data.hasTixApiAccess}}
      el-descriptions-item(label="has4SData") {{data.has4SData}}
      el-descriptions-item(label="has4SDataTixApi") {{data.has4SDataTixApi}}
      el-descriptions-item(label="bitNodeN") {{data.bitNodeN}}
      el-descriptions-item(label="tor") {{data.tor}}
      el-descriptions-item(label="factions") {{data.factions}}

</template>

<script>
import { EventBus } from '@/eventBus.js'
export default {
  name: 'player',
  components: {},
  props: {
    socket: Object
  },
  data () {
    return {
      data: {},
      money: 0
    }
  },
  mounted: function () {
    let that = this
    this.getData()
    setInterval(function () {
      that.getData()
    }, 1000)
  },
  methods: {
    getData: function () {
      let that = this
      that.loading = true
      that.$axios
        .post(that.$root.URL + '/player')
        .then(function (response) {
          that.data = response.data.data.d
          let sum = response.data.data.d.money
          EventBus.$emit('hacklevel', that.data.hacking)
          that.money =
            sum < 1000
              ? sum
              : sum < 1000000
                ? (sum / 1000).toFixed(2) + 'k'
                : sum < 1000000000
                  ? (sum / 1000000).toFixed(2) + 'm'
                  : sum < 1000000000000
                    ? (sum / 1000000000).toFixed(2) + 'b'
                    : (sum / 1000000000000).toFixed(2) + 't'
        })
        .catch(function (error) {
          console.log(error)
          that.loading = false
          that.$message.error(error.toString())
        })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped></style>
